package mipo.top.system.controller;


import mipo.top.base.util.JsonResult;
import mipo.top.base.util.PageUtil;
import mipo.top.system.domain.Menu;
import mipo.top.system.query.MenuQuery;
import mipo.top.system.service.IMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    private IMenuService menuService;

    @GetMapping
    public List<Menu> sad(){
        return menuService.findall();
    }

    @PutMapping
    public JsonResult su(@RequestBody Menu menu){
        try {
            if(menu.getId()==null){
                menuService.save(menu);
            }else{
                menuService.update(menu);
            }
            return JsonResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.me().setMsg("错误数据");
        }
    }

    @DeleteMapping("/{id}")
    public void adw(@PathVariable("id") Long id){
        menuService.remove(id);
    }

    @PostMapping
    public PageUtil<Menu> asp(@RequestBody MenuQuery menuQuery){
        return menuService.queryData(menuQuery);
    }
    @PatchMapping
    private void bacthDel(@RequestBody List<Long> ids){
        menuService.patchremove(ids);
    }

    @GetMapping("/frist")
    public List<Menu> fristData(){
        return menuService.fristData();
    }
    @GetMapping("/tree")
    public List<Menu> treeData(){
        return menuService.treeData();
    }
}
